package com.hongyuan.sellfitness.ui.find.view_mode;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;
import com.hongyuan.mvvmhabitx.binding.command.BindingCommand;
import com.hongyuan.sellfitness.base.Constants;
import com.hongyuan.sellfitness.base.CustomViewModel;
import com.hongyuan.sellfitness.base.ItemViewModel;
import com.hongyuan.sellfitness.ui.find.activity.PostDetailsActivity;
import com.hongyuan.sellfitness.ui.find.beans.FindChildBean;
import com.hongyuan.sellfitness.ui.person.activity.UserInfoActivity;

public class FindChildItemViewModel extends ItemViewModel<CustomViewModel> {

    //是否为用户主页
    public boolean isHomePage;

    public ObservableField<FindChildBean.ListBean> entity = new ObservableField<>();

    public FindChildItemViewModel(@NonNull CustomViewModel viewModel,FindChildBean.ListBean bean) {
        super(viewModel);
        entity.set(bean);
    }

    //去主页
    public BindingCommand goHomePage = new BindingCommand(() -> {
        if(!isHomePage){
            Bundle bundle = new Bundle();
            bundle.putString("user_id",String.valueOf(entity.get().getM_id()));
            bundle.putString("userPhone",entity.get().getM_mobile());
            viewModel.startActivity(UserInfoActivity.class,bundle);
        }
    });

    //去帖子详情
    public BindingCommand goDetails = new BindingCommand(() -> {
        Bundle bundle = new Bundle();
        bundle.putString("circle_id",String.valueOf(entity.get().getCircle_id()));
        viewModel.startActivity(PostDetailsActivity.class,bundle);
    });

    //帖子点赞
    public BindingCommand addPraise = new BindingCommand(() -> {
        //赋予操作对象
        viewModel.itemClick(this);

        //设置请求参数
        viewModel.setParams("circle_id",String.valueOf(entity.get().getCircle_id()));
        if(entity.get().getIs_praise() == 0){
            //点赞
            viewModel.requestData(Constants.ADD_CIRCLE_PRAISE);
        }else{
            //取消点赞
            viewModel.requestData(Constants.CANCEL_CIRCLE_PRAISE);
        }
    });

    /*
    * 是否需要显示审核状态
    * */
    public boolean isVerify(){
        if(isHomePage && viewModel.userToken.getM_mobile().equals(entity.get().getM_mobile())
            && (entity.get().getCircle_state() == 0 || entity.get().getCircle_state() == 2)){
            return true;
        }else{
            return false;
        }
    }

    /*
    * 显示的状态描述
    * */
    public String isVerifyText(){
        if(entity.get().getCircle_state() == 0){
            return "审核中";
        }else if(entity.get().getCircle_state() == 2){
            return "审核未通过";
        }else{
            return "";
        }
    }
}
